﻿using BlogDemo.Core.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlogDemo.Infrastructure.Configuration
{
    public class BlogConfiguration : IEntityTypeConfiguration<Blog>
    {
        public void Configure(EntityTypeBuilder<Blog> builder)
        {
            builder.HasKey(x => x.Id);

            builder.Property(x => x.Name).HasMaxLength(256);
            //.HasComputedColumnSql("[LastName] + ', ' + [FirstName]");
            // .ValueGeneratedOnAdd();



            builder.Property(p => p.Timestamp)
                .IsRowVersion();

            //Blog -> BlogImage （一对一）
            builder.HasOne(b => b.Image)
                .WithOne(i => i.Blog)
                .HasForeignKey<BlogImage>(b => b.BlogId);


            //Blog -> Post （一对多）
            //builder.HasOne(p => p.Blog)
            //    .WithMany(b => b.Posts)
        }
    }
}
